package tweeter_parser;

import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CentralizedParser {
	public static void main(String[] args) {
		Map<Integer, List<Event>> experiment = null;
		Map<Integer,List<Integer>> registrations = null;
		try {
			experiment = CentralizedParser.parseDirectory("C:/Users/gilga/workspace/ConformityParser/event/event/1/",6,7);
			registrations = CentralizedParser.parseRegistrations("C:/Users/gilga/workspace/ConformityParser/follower/follower/1/", experiment.keySet());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(experiment.size());
		System.out.println(registrations.size());
		int publications =0;
		for (List<Event> events : experiment.values()) {
			publications+= events.size();
		}
		int subscriptions =0;
		for (List<Integer> subs : registrations.values()) {
			subscriptions+= subs.size();
		}
		System.out.println(subscriptions);
		
	}
	
	
	
	public static Map<Integer,List<Event>> parseDirectory(String filepath,double from, double to) throws Exception
	{
		File dir = new File(filepath);
		if(!dir.isDirectory())
			throw new Exception("Not a directory");
		Map<Integer,List<Event>> result = new HashMap<Integer, List<Event>>();
		File[] files = dir.listFiles();
		SingleFileParser sfp;
		for (File file : files) {
			sfp = new SingleFileParser(file.getPath(),from,to);
			if(!sfp.myEvents.isEmpty())
			{
				result.put(sfp.myID, sfp.myEvents);
			}
			
		}
		return result;
		
	}
	
	public static Map<Integer,List<Integer>> parseRegistrations(String followerDirectory,Collection<Integer> world) throws Exception
	{
		File dir = new File(followerDirectory);
		if(!dir.isDirectory())
			throw new Exception("Not a directory");
		Map<Integer,List<Integer>> result = new HashMap<Integer, List<Integer>>();
		File[] files = dir.listFiles();
		SingleFollowerParser sfp;
		for (File file : files) {
			sfp = new SingleFollowerParser(file.getPath(),world);
			if(sfp.registrations.isEmpty())
				continue;
			result.put(sfp.myID, sfp.registrations);
		}
		return result;
		
	}
}
